import axios from 'axios';

let CancelToken = axios.CancelToken

axios.create({
	timeout:15000,
	widthCredentials: true,
	headers: {
		'Content-Type': 'application/x-www-form-urlencoded',
	}
})

axios.interceptors.request.use(config => {
	let token = window.localStorage.getItem("token");
	config.headers.common['X-Requested-With'] = 'XMLHttpRequest';
	config.headers.common['request_access_token'] = token;
	return config
}, error => { 
	return Promise.reject(error)
})

axios.interceptors.response.use(response=>{
	if(response.data && response.data.status) {
		return response.data;
	} 
	return response;
},
    error => {
        return Promise.reject(error)
    }
)

export default axios;